﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.CrossdockServiceRef;

    public class CrossdockServiceClientProxy : BasePage
    {
        public string DeleteApportionRuleInfo(List<string> OwnerIDs, List<string> CustomerIDs, List<string> SeqNo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.DeleteApportionRuleInfo(OwnerIDs, CustomerIDs, SeqNo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteLaneInfo(List<string> laneInfoIDs)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.DeleteLaneInfo(laneInfoIDs, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteOppOrderRuleDetailInfo(List<string> opporderRuleIDs, List<string> lineIDs)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.DeleteOppOrderRuleDetailInfo(opporderRuleIDs, lineIDs, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteOppOrderRuleInfo(List<string> OppOrderRuleIDs)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.DeleteOppOrderRuleInfo(OppOrderRuleIDs, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteXordersInfo(List<string> xOrderIDs)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.DeleteXordersInfo(xOrderIDs, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public DataSet GetAllApportionRuleInfo()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                ds = client.GetAllApportionRuleInfo(pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetAllLaneInfo()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                ds = client.GetAllLaneInfo(pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetAllOpporderRuleDetail()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                ds = client.GetAllOpporderRuleDetail(pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetAllOppOrderRuleInfo()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                ds = client.GetAllOppOrderRuleInfo(pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public ApportionRuleInfo GetApportionRuleInfoByID(string OwnerID, string CustomerID, string SeqNo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            ApportionRuleInfo apportionRuleInfo = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                apportionRuleInfo = client.GetApportionRuleInfoByID(OwnerID, CustomerID, SeqNo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return apportionRuleInfo;
        }

        public DataSet GetApportionRuleInfoByQueryEntity(ApportionRuleQueryEntity apportionRuleQuery)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                ds = client.GetApportionRuleInfoByQueryEntity(apportionRuleQuery, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public List<ApportionRuleInfo> GetApportionRuleListByID(string OwnerID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            List<ApportionRuleInfo> apportionRuleInfoList = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                apportionRuleInfoList = client.GetApportionRuleListByID(OwnerID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return apportionRuleInfoList;
        }

        public static CrossdockServiceClientProxy GetInstance()
        {
            return new CrossdockServiceClientProxy();
        }

        public LaneInfo GetLaneInfoByID(string laneID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            LaneInfo lanInfo = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                lanInfo = client.GetLaneInfoByID(laneID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return lanInfo;
        }

        public DataSet GetLaneInfoByQueryEntity(LaneQueryEntity c)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                ds = client.GetLaneInfoByQueryEntity(c, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetOppOrderRuleDetailByQueryEntity(OppOrderRuleDetailQueryEntity oppOrderRuleDetailQuery)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                ds = client.GetOppOrderRuleDetailByQueryEntity(oppOrderRuleDetailQuery, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public OppOrderRuleDetailInfo GetOppOrderRuleDetailInfoByID(string opporderRuleID, string lineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService"))
            {
                return client.GetOppOrderRuleDetailInfoByID(opporderRuleID, lineID, pubParasInfo);
            }
        }

        public List<OppOrderRuleDetailInfo> GetOpporderRuleDetailListByID(string opporderRuleID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService"))
            {
                return client.GetOpporderRuleDetailListByID(opporderRuleID, pubParasInfo);
            }
        }

        public OppOrderRuleInfo GetOppOrderRuleIDByID(string opporderRuleID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService"))
            {
                return client.GetOppOrderRuleIDByID(opporderRuleID, pubParasInfo);
            }
        }

        public DataSet GetOppOrderRuleInfoByQueryEntity(OppOrderRuleQueryEntity oppOrderRuleQuery)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                ds = client.GetOppOrderRuleInfoByQueryEntity(oppOrderRuleQuery, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public XorderDetailInfo GetXorderDetailInfoByID(string xOrderID, string lineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            XorderDetailInfo xorderDetailInfo = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                xorderDetailInfo = client.GetXorderDetailInfoByID(xOrderID, lineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return xorderDetailInfo;
        }

        public XordersInfo GetXordersInfoByID(string xOrderID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            XordersInfo xordersInfo = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                xordersInfo = client.GetXordersInfoByID(xOrderID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return xordersInfo;
        }

        public DataSet GetXordersInfoByQueryEntity(XordersQueryEntity xordersQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                ds = client.GetXordersInfoByQueryEntity(xordersQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetXordersReceiptPurchaseOrderByQueryList(XordersQueryEntity xordersQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                ds = client.GetXordersReceiptPurchaseOrderByQueryList(xordersQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InsertApportionRuleInfo(ApportionRuleInfo apportionRuleInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.InsertApportionRuleInfo(apportionRuleInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertLaneInfo(LaneInfo laneInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.InsertLane(laneInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertOppOrderRuleDetailInfo(OppOrderRuleDetailInfo oppOrderRuleDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.InsertOppOrderRuleDetailInfo(oppOrderRuleDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertOppOrderRuleInfo(OppOrderRuleInfo oppOrderRuleInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.InsertOppOrderRuleInfo(oppOrderRuleInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertXordersInfo(XordersInfo xordersInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.InsertXordersInfo(xordersInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateApportionRuleInfo(ApportionRuleInfo apportionRuleInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.UpdateApportionRuleInfo(apportionRuleInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateLaneInfo(LaneInfo laneInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.UpdateLane(laneInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateOppOrderRuleDetailInfo(OppOrderRuleDetailInfo oppOrderRuleDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.UpdateOppOrderRuleDetailInfo(oppOrderRuleDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateOppOrderRuleInfo(OppOrderRuleInfo oppOrderRuleInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.UpdateOppOrderRuleInfo(oppOrderRuleInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateXordersInfo(XordersInfo xordersInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.UpdateXordersInfo(xordersInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateXOrdreDetail(XorderDetailInfo xorderDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.UpdateXOrdreDetail(xorderDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string XorderAllocate(string receiptID, string xorderID, List<string> lineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.XorderAllocate(receiptID, xorderID, lineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string XPickDetailShipping(List<string> xpickDetailID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            CrossdockServiceClient client = new CrossdockServiceClient("WSHttpBinding_ICrossdockService");
            try
            {
                result = client.XPickDetailShipping(xpickDetailID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }
    }
}

